/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = jolt_dataxfer.c                                    */
/*  NOTE      =                                                    */
/*  DATE      = 2015/06/03 by songbb                               */
/*******************************************************************/

#include "conntrack.h"
#include "frct_comm.h"

#include "jolt_core.h"
#include "jolt_comm.h"
#include "jolt_mar.h"
#include "jolt_dataxfer.h"

/*******************************************************************************
*  FUNC     :  解析LOGON请求
*  ARGS     :  *p_st_conn                               (ct信息)
*           :  *p_st_sess                               (Jolt私有的session)
*           :  *p_st_jolt_packet                        (Jolt数据包)
*           :  *p_st_hash_report                        (数据上报)
*  RTN      :  0                                        (FR_SUCC)
*              1                                        (FR_FAIL)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __jolt_logon_req(Conntrack *p_st_conn
                                , L7session_jolt *p_st_sess
                                , L7_jolt_packet *p_st_jolt_packet)
{
    unsigned int ui_msgparam = 0;
    int i_joltvers = 0;
    unsigned int ui_username_len = 0;
    unsigned int ui_userrole_len = 0;
    char *p_passwd = NULL;
    unsigned int ui_passwd_len = 0;
    char *p_binpwd = NULL;
    unsigned int ui_binpwd_len = 0;
    char *p_appasswd = NULL;
    unsigned int ui_appasswd_len = 0;

    if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (ui_msgparam != APM_JOLT_PARM_JOLTVERS)
        goto error;
    if (jolt_mar_get_int(APM_JOLT_PARM_JOLTVERS, p_st_jolt_packet, &i_joltvers) != FR_SUCC)
        goto error;

    while (bytebuff_remaining(p_st_jolt_packet->p_st_packet) > 0)
    {
        if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
        switch (ui_msgparam)
        {
            case APM_JOLT_PARM_USERNAME:
                jolt_free((void **) &p_st_sess->p_username);
                if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_USERNAME, p_st_jolt_packet, &p_st_sess->p_username, &ui_username_len) != FR_SUCC)
                    goto error;
                JOLT_PRINT_FATAL("username:[%s]\n", p_st_sess->p_username);
                break;
            case APM_JOLT_PARM_USERROLE:
                jolt_free((void **) &p_st_sess->p_userrole);
                if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_USERROLE, p_st_jolt_packet, &p_st_sess->p_userrole, &ui_userrole_len) != FR_SUCC)
                    goto error;
                JOLT_PRINT_FATAL("userrole:[%s]\n", p_st_sess->p_userrole);
                break;
            case APM_JOLT_PARM_PASSWD:
                if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_PASSWD, p_st_jolt_packet, &p_passwd, &ui_passwd_len) != FR_SUCC)
                    goto error;
                jolt_free((void **) &p_passwd);
                break;
            case APM_JOLT_PARM_BINPWD:
                if (jolt_mar_get_bytes(APM_JOLT_PARM_BINPWD, p_st_jolt_packet, &p_binpwd, &ui_binpwd_len) != FR_SUCC)
                    goto error;
                jolt_free((void **) &p_binpwd);
                break;
            case APM_JOLT_PARM_APPASSWD:
                if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_APPASSWD, p_st_jolt_packet, &p_appasswd, &ui_appasswd_len) != FR_SUCC)
                    goto error;
                jolt_free((void **) &p_appasswd);
                break;
            default:
                goto error;
        }
    }

    return FR_SUCC;
error:
    jolt_free((void **) &p_st_sess->p_username);
    jolt_free((void **) &p_st_sess->p_userrole);
    return FR_FAIL;
}

/*******************************************************************************
*  FUNC     :  解析CALL请求
*  ARGS     :  *p_st_conn                               (ct信息)
*           :  *p_st_sess                               (Jolt私有的session)
*           :  *p_st_jolt_packet                        (Jolt数据包)
*           :  *p_st_hash_report                        (数据上报)
*  RTN      :  0                                        (FR_SUCC)
*              1                                        (FR_FAIL)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __jolt_call_req(Conntrack *p_st_conn
                            , L7session_jolt *p_st_sess
                            , L7_jolt_packet *p_st_jolt_packet
                            , Frhash_header *p_st_hash_report)
{
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_jolt_private *p_st_session_private = (L7session_jolt_private *) frct_get_session_private(p_st_session);
    L7_jolt_stmt *p_st_jolt_stmt = p_st_session_private->p_st_jolt_stmt;
    L7_jolt_msg_data *p_st_jolt_msg_data = NULL;
    Frlist_node *p_st_node = NULL;
    unsigned int ui_msgparam = 0;
    unsigned int ui_name_len = 0;
    int i_version = 0;
    int i_flags = 0;
    int i_requestver = 0;
    int i_priority = 0;
    char *p_principalname = NULL;
    unsigned int ui_principalname_len = 0;
    char *p_realm = NULL;
    unsigned int ui_realm_len = 0;
    unsigned int ui_mbencoding_len = 0;
    int i_datalen = 0;
    int i_pos_start = 0;
    unsigned int ui_type = 0;
    int i_definition_index = 0;
    short s_tmp = 0;
    int i_tmp = 0;
    char c_tmp = 0;
    float f_tmp = 0;
    double d_tmp = 0;
    char *p_tmp = NULL;
    unsigned int ui_tmp_len = 0;
    long long ll_tmp = 0LL;
    char *p_service_name = NULL;
    char *p_title = NULL;

    jolt_init_stmt(p_st_session_private->p_st_jolt_stmt);

    p_st_jolt_stmt->ui_msg_id = p_st_jolt_packet->ui_msg_id;

    if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (ui_msgparam != APM_JOLT_PARM_NAME)
        goto error;
    if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_NAME, p_st_jolt_packet, &p_service_name, &ui_name_len) != FR_SUCC)
        goto error;
    JOLT_PRINT_FATAL("name:[%s]\n", p_service_name);

    if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (ui_msgparam != APM_JOLT_PARM_VERSION)
        goto error;
    if (jolt_mar_get_int(APM_JOLT_PARM_VERSION, p_st_jolt_packet, &i_version) != FR_SUCC)
        goto error;
    JOLT_PRINT_FATAL("version:[%d]\n", i_version);

    if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (ui_msgparam != APM_JOLT_PARM_FLAGS)
        goto error;
    if (jolt_mar_get_int(APM_JOLT_PARM_FLAGS, p_st_jolt_packet, &i_flags) != FR_SUCC)
        goto error;
    JOLT_PRINT_FATAL("flags:[%d]\n", i_flags);

    if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (ui_msgparam == APM_JOLT_PARM_REQUESTVER)
    {
        if (jolt_mar_get_int(APM_JOLT_PARM_REQUESTVER, p_st_jolt_packet, &i_requestver) != FR_SUCC)
            goto error;
        JOLT_PRINT_FATAL("requestver:[%d]\n", i_requestver);

        if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
    }

    if (ui_msgparam == APM_JOLT_PARM_PRIORITY)
    {
        if (jolt_mar_get_int(APM_JOLT_PARM_PRIORITY, p_st_jolt_packet, &i_priority) != FR_SUCC)
            goto error;
        JOLT_PRINT_FATAL("priority:[%d]\n", i_priority);

        if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
    }

    if (ui_msgparam == APM_JOLT_PARM_PRINCIPALNAME)
    {
        if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_PRINCIPALNAME, p_st_jolt_packet, &p_principalname, &ui_principalname_len) != FR_SUCC)
            goto error;
        JOLT_PRINT_FATAL("principalname:[%s]\n", p_principalname);

        if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
    }

    if (ui_msgparam == APM_JOLT_PARM_REALM)
    {
        if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_REALM, p_st_jolt_packet, &p_realm, &ui_realm_len) != FR_SUCC)
            goto error;
        JOLT_PRINT_FATAL("realm:[%s]\n", p_realm);

        if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
    }

    jolt_free((void **) &(p_st_sess->p_mbencoding));
    if (ui_msgparam == APM_JOLT_PARM_MBENCODING)
    {
        if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_MBENCODING, p_st_jolt_packet, &(p_st_sess->p_mbencoding), &ui_mbencoding_len) != FR_SUCC)
            goto error;
        JOLT_PRINT_FATAL("mbencoding:[%s]\n", p_st_sess->p_mbencoding);

        if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
    }

    if (ui_msgparam == APM_JOLT_PARM_DATA)
    {
        if (jolt_mar_get_int(APM_JOLT_PARM_DATA, p_st_jolt_packet, &i_datalen) != FR_SUCC)
            goto error;

        while (i_datalen > 0)
        {
            i_pos_start = bytebuff_getPosition(p_st_jolt_packet->p_st_packet);

            if (bytebuff_get_char(p_st_jolt_packet->p_st_packet, (uint8_t *) &ui_type) != FR_SUCC)
                goto error;
            ui_type = ui_type / 2 << 25;
            if (bytebuff_skip(p_st_jolt_packet->p_st_packet, 2) != FR_SUCC)
                goto error;
            if (bytebuff_get_char(p_st_jolt_packet->p_st_packet, (uint8_t *) &i_definition_index) != FR_SUCC)
                goto error;

            JOLT_PRINT_CRIT("ui_type:[%d]\n", ui_type>>25);
            switch (ui_type >> 25)
            {
                case APM_JOLT_SSHORT:
                    if (jolt_mar_get_short(ui_type, p_st_jolt_packet, &s_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SSHORT;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->s_short = s_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] short:[%d]\n", i_definition_index, s_tmp);
                    break;
                case APM_JOLT_SINT:
                    if (jolt_mar_get_int(ui_type, p_st_jolt_packet, &i_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SINT;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->i_int = i_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] int:[%d]\n", i_definition_index, i_tmp);
                    break;
                case APM_JOLT_SBYTE:
                    if (jolt_mar_get_byte(ui_type, p_st_jolt_packet, &c_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SBYTE;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->c_char = c_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] byte:[%d]\n", i_definition_index, c_tmp);
                    break;
                case APM_JOLT_SFLOAT:
                    if (jolt_mar_get_float(ui_type, p_st_jolt_packet, &f_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SFLOAT;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->f_float = f_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] float:[%f]\n", i_definition_index, f_tmp);
                    break;
                case APM_JOLT_SDOUBLE:
                    if (jolt_mar_get_double(ui_type, p_st_jolt_packet, &d_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SDOUBLE;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->d_double = d_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] double:[%lf]\n", i_definition_index, d_tmp);
                    break;
                case APM_JOLT_SSTRING:
                    if (jolt_mar_get_string(p_st_sess, ui_type, p_st_jolt_packet, &p_tmp, &ui_tmp_len) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SSTRING;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->p_string = p_tmp;
                    p_st_jolt_msg_data->i_string_len = ui_tmp_len;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] string:[%s]\n", i_definition_index, p_tmp);
                    break;
                case APM_JOLT_SBINARY:
                    if (jolt_mar_get_bytes(ui_type, p_st_jolt_packet, &p_tmp, &ui_tmp_len) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SBINARY;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->p_string = p_tmp;
                    p_st_jolt_msg_data->i_string_len = ui_tmp_len;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    break;
                case APM_JOLT_SSTRUCT:
                    if (jolt_mar_get_struct(ui_type, p_st_jolt_packet, &p_tmp, &ui_tmp_len) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SSTRUCT;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->p_string = p_tmp;
                    p_st_jolt_msg_data->i_string_len = ui_tmp_len;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    break;
                case APM_JOLT_SMBSTRING:
                    if (jolt_mar_get_string(p_st_sess, ui_type, p_st_jolt_packet, &p_tmp, &ui_tmp_len) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SMBSTRING;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->p_string = p_tmp;
                    p_st_jolt_msg_data->i_string_len = ui_tmp_len;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] mbstring:[%s]\n", i_definition_index, p_tmp);
                    break;
                case APM_JOLT_SBOOLEAN:
                    if (jolt_mar_get_boolean(ui_type, p_st_jolt_packet, &i_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SBOOLEAN;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->s_boolean = (short) i_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] boolean:[%d]\n", i_definition_index, p_st_jolt_msg_data->s_boolean);
                    break;
                case APM_JOLT_SLONG:
                    if (jolt_mar_get_long(ui_type, p_st_jolt_packet, &ll_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SLONG;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->ll_long = ll_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] long:[%lld]\n", i_definition_index, ll_tmp);
                    break;
                default:
                    goto error;
            }

            i_datalen -= bytebuff_getPosition(p_st_jolt_packet->p_st_packet) - i_pos_start;
        }
    }

    if ((p_title = (char *) frmalloc((ui_name_len + strlen("call ") + 1) * sizeof(char))) == NULL)
    {
        JOLT_MALLOCK_ERR;
        goto error;
    }

    snprintf(p_title, ui_name_len + strlen("call ") + 1, "call %s", p_service_name);

    if (jolt_report_msg_data_req(p_st_conn, p_st_sess, p_title, p_service_name, (char *) "call", p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
        goto error;

    jolt_free((void **) &p_service_name);
    jolt_free((void **) &p_title);
    jolt_free((void **) &p_principalname);
    jolt_free((void **) &p_realm);
    return FR_SUCC;
error:
    jolt_free((void **) &p_service_name);
    jolt_free((void **) &p_title);
    jolt_free((void **) &p_principalname);
    jolt_free((void **) &p_realm);
    jolt_free((void **) &p_tmp);
    return FR_FAIL;
}

/*******************************************************************************
*  FUNC     :  解析CALL响应
*  ARGS     :  *p_st_conn                               (ct信息)
*           :  *p_st_sess                               (Jolt私有的session)
*           :  *p_st_jolt_packet                        (Jolt数据包)
*           :  *p_st_hash_report                        (数据上报)
*  RTN      :  0                                        (FR_SUCC)
*              1                                        (FR_FAIL)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __jolt_call_resp(Conntrack *p_st_conn
                                , L7session_jolt *p_st_sess
                                , L7_jolt_packet *p_st_jolt_packet
                                , Frhash_header *p_st_hash_report)
{
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_jolt_private *p_st_session_private = (L7session_jolt_private *) frct_get_session_private(p_st_session);
    L7_jolt_stmt *p_st_jolt_stmt = p_st_session_private->p_st_jolt_stmt;
    L7_jolt_msg_data *p_st_jolt_msg_data = NULL;
    Frlist_node *p_st_node = NULL;
    unsigned int ui_msgparam = 0;
    int i_datalen = 0;
    int i_errno = 0;
    unsigned int ui_reason_len = 0;
    int i_clientdata = 0;
    char *p_reason = NULL;
    int i_pos_start = 0;
    unsigned int ui_type = 0;
    int i_definition_index = 0;
    short s_tmp = 0;
    int i_tmp = 0;
    char c_tmp = 0;
    float f_tmp = 0;
    double d_tmp = 0;
    char *p_tmp = NULL;
    unsigned int ui_tmp_len = 0;
    long long ll_tmp = 0LL;

    if (p_st_jolt_stmt->ui_msg_id != p_st_jolt_packet->ui_msg_id)
    {
        JOLT_PRINT_EMERG("different msg id between request and response\n");
        goto error;
    }

    frlist_remove_all(p_st_jolt_stmt->p_list_msg_data, jolt_msg_data_node_free);

    if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (ui_msgparam == APM_JOLT_PARM_DATA)
    {
        if (jolt_mar_get_int(APM_JOLT_PARM_DATA, p_st_jolt_packet, &i_datalen) != FR_SUCC)
            goto error;

        while (i_datalen > 0)
        {
            i_pos_start = bytebuff_getPosition(p_st_jolt_packet->p_st_packet);

            if (bytebuff_get_char(p_st_jolt_packet->p_st_packet, (uint8_t *) &ui_type) != FR_SUCC)
                goto error;
            ui_type = ui_type / 2 << 25;
            if (bytebuff_skip(p_st_jolt_packet->p_st_packet, 2) != FR_SUCC)
                goto error;
            if (bytebuff_get_char(p_st_jolt_packet->p_st_packet, (uint8_t *) &i_definition_index) != FR_SUCC)
                goto error;

            JOLT_PRINT_CRIT("ui_type:[%d]\n", ui_type>>25);
            switch (ui_type >> 25)
            {
                case APM_JOLT_SSHORT:
                    if (jolt_mar_get_short(ui_type, p_st_jolt_packet, &s_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SSHORT;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->s_short = s_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] short:[%d]\n", i_definition_index, s_tmp);
                    break;
                case APM_JOLT_SINT:
                    if (jolt_mar_get_int(ui_type, p_st_jolt_packet, &i_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SINT;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->i_int = i_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] int:[%d]\n", i_definition_index, i_tmp);
                    break;
                case APM_JOLT_SBYTE:
                    if (jolt_mar_get_byte(ui_type, p_st_jolt_packet, &c_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SBYTE;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->c_char = c_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] byte:[%d]\n", i_definition_index, c_tmp);
                    break;
                case APM_JOLT_SFLOAT:
                    if (jolt_mar_get_float(ui_type, p_st_jolt_packet, &f_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SFLOAT;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->f_float = f_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] float:[%f]\n", i_definition_index, f_tmp);
                    break;
                case APM_JOLT_SDOUBLE:
                    if (jolt_mar_get_double(ui_type, p_st_jolt_packet, &d_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SDOUBLE;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->d_double = d_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] double:[%lf]\n", i_definition_index, d_tmp);
                    break;
                case APM_JOLT_SSTRING:
                    if (jolt_mar_get_string(p_st_sess, ui_type, p_st_jolt_packet, &p_tmp, &ui_tmp_len) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SSTRING;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->p_string = p_tmp;
                    p_st_jolt_msg_data->i_string_len = ui_tmp_len;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] string:[%s]\n", i_definition_index, p_tmp);
                    break;
                case APM_JOLT_SBINARY:
                    if (jolt_mar_get_bytes(ui_type, p_st_jolt_packet, &p_tmp, &ui_tmp_len) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SBINARY;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->p_string = p_tmp;
                    p_st_jolt_msg_data->i_string_len = ui_tmp_len;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    break;
                case APM_JOLT_SSTRUCT:
                    if (jolt_mar_get_struct(ui_type, p_st_jolt_packet, &p_tmp, &ui_tmp_len) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SSTRUCT;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->p_string = p_tmp;
                    p_st_jolt_msg_data->i_string_len = ui_tmp_len;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    break;
                case APM_JOLT_SMBSTRING:
                    if (jolt_mar_get_string(p_st_sess, ui_type, p_st_jolt_packet, &p_tmp, &ui_tmp_len) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SMBSTRING;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->p_string = p_tmp;
                    p_st_jolt_msg_data->i_string_len = ui_tmp_len;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] mbstring:[%s]\n", i_definition_index, p_tmp);
                    break;
                case APM_JOLT_SBOOLEAN:
                    if (jolt_mar_get_boolean(ui_type, p_st_jolt_packet, &i_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SBOOLEAN;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->s_boolean = (short) i_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] boolean:[%d]\n", i_definition_index, p_st_jolt_msg_data->s_boolean);
                    break;
                case APM_JOLT_SLONG:
                    if (jolt_mar_get_long(ui_type, p_st_jolt_packet, &ll_tmp) != FR_SUCC)
                        goto error;
                    if ((p_st_jolt_msg_data = (L7_jolt_msg_data *) frmalloc(sizeof(L7_jolt_msg_data))) == NULL)
                    {
                        JOLT_MALLOCK_ERR;
                        goto error;
                    }
                    memset(p_st_jolt_msg_data, 0x00, sizeof(L7_jolt_msg_data));
                    p_st_jolt_msg_data->ui_type = APM_JOLT_SLONG;
                    p_st_jolt_msg_data->i_index = i_definition_index;
                    p_st_jolt_msg_data->ll_long = ll_tmp;
                    p_st_node = frlist_node_create(p_st_jolt_msg_data);
                    frlist_push(p_st_jolt_stmt->p_list_msg_data, p_st_node);
                    JOLT_PRINT_ALERT("idx:[%d] long:[%lld]\n", i_definition_index, ll_tmp);
                    break;
                default:
                    goto error;
            }

            i_datalen -= bytebuff_getPosition(p_st_jolt_packet->p_st_packet) - i_pos_start;
        }

        if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
    }

    if (ui_msgparam == APM_JOLT_PARM_ERRNO)
    {
        if (jolt_mar_get_int(APM_JOLT_PARM_ERRNO, p_st_jolt_packet, &i_errno) != FR_SUCC)
            goto error;
        if (i_errno > 0 && bytebuff_remaining(p_st_jolt_packet->p_st_packet) > 0)
        {
            if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
                goto error;
            if (ui_msgparam == APM_JOLT_PARM_REASON)
            {
                if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_REASON, p_st_jolt_packet, &p_reason, &ui_reason_len) != FR_SUCC)
                    goto error;
                JOLT_PRINT_FATAL("reason:[%s]\n", p_reason);

                if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
                    goto error;
            }
        }
    }

    if (ui_msgparam == APM_JOLT_PARM_CLIENTDATA)
    {
        if (jolt_mar_get_int(APM_JOLT_PARM_CLIENTDATA, p_st_jolt_packet, &i_clientdata) != FR_SUCC)
            goto error;
    }

    if (jolt_report_msg_data_resp(p_st_conn, i_errno, p_reason, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
        goto error;

    jolt_free((void **) &p_reason);
    return FR_SUCC;
error:
    jolt_free((void **) &p_reason);
    return FR_FAIL;
}

/*******************************************************************************
*  FUNC     :  解析TRANS请求
*  ARGS     :  *p_st_conn                               (ct信息)
*           :  *p_st_sess                               (Jolt私有的session)
*           :  *p_st_jolt_packet                        (Jolt数据包)
*           :  *p_st_hash_report                        (数据上报)
*  RTN      :  0                                        (FR_SUCC)
*              1                                        (FR_FAIL)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __jolt_trans_req(Conntrack *p_st_conn
                            , L7session_jolt *p_st_sess
                            , L7_jolt_packet *p_st_jolt_packet
                            , Trans_type trans_type
                            , Frhash_header *p_st_hash_report)
{
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_jolt_private *p_st_session_private = (L7session_jolt_private *) frct_get_session_private(p_st_session);
    L7_jolt_stmt *p_st_jolt_stmt = p_st_session_private->p_st_jolt_stmt;
    char *p_title = NULL;

    jolt_init_stmt(p_st_session_private->p_st_jolt_stmt);

    p_st_jolt_stmt->ui_msg_id = p_st_jolt_packet->ui_msg_id;
    switch (trans_type)
    {
        case TRANS_BEGIN:
            p_title = frstrdup("begin");
            break;
        case TRANS_COMMIT:
            p_title = frstrdup("commit");
            break;
        case TRANS_ROLLBACK:
            p_title = frstrdup("rollback");
            break;
        case TRANS_SUSPEND:
            p_title = frstrdup("suspend");
            break;
        case TRANS_RESUME:
            p_title = frstrdup("resume");
            break;
        default:
            goto error;
    }

    if (jolt_report_msg_data_req(p_st_conn, p_st_sess, p_title, NULL, p_title, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
        goto error;

    jolt_free((void **) &p_title);
    return FR_SUCC;
error:
    jolt_free((void **) &p_title);
    return FR_FAIL;
}

/*******************************************************************************
*  FUNC     :  解析TRANS响应
*  ARGS     :  *p_st_conn                               (ct信息)
*           :  *p_st_sess                               (Jolt私有的session)
*           :  *p_st_jolt_packet                        (Jolt数据包)
*           :  *p_st_hash_report                        (数据上报)
*  RTN      :  0                                        (FR_SUCC)
*              1                                        (FR_FAIL)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __jolt_trans_resp(Conntrack *p_st_conn
                                , L7session_jolt *p_st_sess
                                , L7_jolt_packet *p_st_jolt_packet
                                , Frhash_header *p_st_hash_report)
{
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_jolt_private *p_st_session_private = (L7session_jolt_private *) frct_get_session_private(p_st_session);
    L7_jolt_stmt *p_st_jolt_stmt = p_st_session_private->p_st_jolt_stmt;
    unsigned int ui_msgparam = 0;
    int i_datalen = 0;
    int i_errno = 0;
    unsigned int ui_reason_len = 0;
    char *p_reason = NULL;

    if (p_st_jolt_stmt->ui_msg_id != p_st_jolt_packet->ui_msg_id)
    {
        JOLT_PRINT_EMERG("different msg id between request and response\n");
        goto error;
    }

    if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (ui_msgparam == APM_JOLT_PARM_DATA)
    {
        if (jolt_mar_get_int(APM_JOLT_PARM_DATA, p_st_jolt_packet, &i_datalen) != FR_SUCC)
            goto error;

        if (bytebuff_skip(p_st_jolt_packet->p_st_packet, (size_t) i_datalen) != FR_SUCC)
            goto error;

        if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
    }

    if (ui_msgparam == APM_JOLT_PARM_ERRNO)
    {
        if (jolt_mar_get_int(APM_JOLT_PARM_ERRNO, p_st_jolt_packet, &i_errno) != FR_SUCC)
            goto error;
        if (i_errno > 0 && bytebuff_remaining(p_st_jolt_packet->p_st_packet) > 0)
        {
            if (bytebuff_get_int(p_st_jolt_packet->p_st_packet, 4, &ui_msgparam, BYTE_BIG_ENDIAN) != FR_SUCC)
                goto error;
            if (ui_msgparam == APM_JOLT_PARM_REASON)
            {
                if (jolt_mar_get_string(p_st_sess, APM_JOLT_PARM_REASON, p_st_jolt_packet, &p_reason, &ui_reason_len) != FR_SUCC)
                    goto error;
                JOLT_PRINT_FATAL("reason:[%s]\n", p_reason);
            }
        }
    }

    if (jolt_report_msg_data_resp(p_st_conn, i_errno, p_reason, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
        goto error;

    return FR_SUCC;
error:
    return FR_FAIL;
}

/*******************************************************************************
*  FUNC     :  解析dataxfer请求
*  ARGS     :  *p_st_conn                               (ct信息)
*           :  *p_st_sess                               (Jolt私有的session)
*           :  *p_st_jolt_packet                        (Jolt数据包)
*           :  *p_st_hash_report                        (数据上报)
*  RTN      :  0                                        (FR_SUCC)
*              1                                        (FR_FAIL)
*  NOTE     :
*******************************************************************************/
int jolt_dataxfer_req(Conntrack *p_st_conn
                    , L7session_jolt *p_st_sess
                    , L7_jolt_packet *p_st_jolt_packet
                    , Frhash_header *p_st_hash_report)
{
    unsigned short us_session_id = 0;
    unsigned short us_jopcode = 0;

    if (bytebuff_skip(p_st_jolt_packet->p_st_packet, APM_JOLT_PKT_HEADER_LEN) != FR_SUCC)
        goto error;

    if (bytebuff_get_short(p_st_jolt_packet->p_st_packet, 2, &us_session_id, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;

    if (bytebuff_get_short(p_st_jolt_packet->p_st_packet, 2, &us_jopcode, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;

    switch (us_jopcode)
    {
        case APM_JOLT_JOPCODE_LOGON_RQST:
            JOLT_PRINT_FATAL("LOGON_RQST\n");
            if (__jolt_logon_req(p_st_conn, p_st_sess, p_st_jolt_packet) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_GETDEF_RQST:
            JOLT_PRINT_FATAL("GETDEF_RQST\n");
            break;
        case APM_JOLT_JOPCODE_GETREC_RQST:
            JOLT_PRINT_FATAL("GETREC_RQST\n");
            break;
        case APM_JOLT_JOPCODE_BEGIN_RQST:
            JOLT_PRINT_FATAL("BEGIN_RQST\n");
            break;
        case APM_JOLT_JOPCODE_COMMIT_RQST:
            JOLT_PRINT_FATAL("COMMIT_RQST\n");
            if (__jolt_trans_req(p_st_conn, p_st_sess, p_st_jolt_packet, TRANS_COMMIT, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_ROLLBACK_RQST:
            JOLT_PRINT_FATAL("ROLLBACK_RQST\n");
            if (__jolt_trans_req(p_st_conn, p_st_sess, p_st_jolt_packet, TRANS_ROLLBACK, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_SUSPEND_RQST:
            JOLT_PRINT_FATAL("SUSPEND_RQST\n");
            if (__jolt_trans_req(p_st_conn, p_st_sess, p_st_jolt_packet, TRANS_SUSPEND, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_RESUME_RQST:
            JOLT_PRINT_FATAL("RESUME_RQST\n");
            if (__jolt_trans_req(p_st_conn, p_st_sess, p_st_jolt_packet, TRANS_RESUME, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_CALL_RQST:
            JOLT_PRINT_FATAL("CALL_RQST\n");
            if (__jolt_call_req(p_st_conn, p_st_sess, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_LOGOFF_RQST:
            JOLT_PRINT_FATAL("LOGOFF_RQST\n");
            break;
        default:
            ;
    }

    return FR_SUCC;
error:
    return FR_FAIL;
}

/*******************************************************************************
*  FUNC     :  解析dataxfer响应
*  ARGS     :  *p_st_conn                               (ct信息)
*           :  *p_st_sess                               (Jolt私有的session)
*           :  *p_st_jolt_packet                        (Jolt数据包)
*           :  *p_st_hash_report                        (数据上报)
*  RTN      :  0                                        (FR_SUCC)
*              1                                        (FR_FAIL)
*  NOTE     :
*******************************************************************************/
int jolt_dataxfer_resp(Conntrack *p_st_conn
                    , L7session_jolt *p_st_sess
                    , L7_jolt_packet *p_st_jolt_packet
                    , Frhash_header *p_st_hash_report)
{
    unsigned short us_session_id = 0;
    unsigned short us_jopcode = 0;

    if (bytebuff_skip(p_st_jolt_packet->p_st_packet, APM_JOLT_PKT_HEADER_LEN) != FR_SUCC)
        goto error;

    if (bytebuff_get_short(p_st_jolt_packet->p_st_packet, 2, &us_session_id, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;

    if (bytebuff_get_short(p_st_jolt_packet->p_st_packet, 2, &us_jopcode, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;

    switch (us_jopcode)
    {
        case APM_JOLT_JOPCODE_LOGON_RESP:
            JOLT_PRINT_FATAL("LOGON_RESP\n");
            break;
        case APM_JOLT_JOPCODE_GETDEF_RESP:
            JOLT_PRINT_FATAL("GETDEF_RESP\n");
            break;
        case APM_JOLT_JOPCODE_GETREC_RESP:
            JOLT_PRINT_FATAL("GETREC_RESP\n");
            break;
        case APM_JOLT_JOPCODE_BEGIN_RESP:
            JOLT_PRINT_FATAL("BEGIN_RESP\n");
            break;
        case APM_JOLT_JOPCODE_COMMIT_RESP:
            JOLT_PRINT_FATAL("COMMIT_RESP\n");
            if (__jolt_trans_resp(p_st_conn, p_st_sess, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_ROLLBACK_RESP:
            JOLT_PRINT_FATAL("ROLLBACK_RESP\n");
            if (__jolt_trans_resp(p_st_conn, p_st_sess, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_SUSPEND_RESP:
            JOLT_PRINT_FATAL("SUSPEND_RESP\n");
            if (__jolt_trans_resp(p_st_conn, p_st_sess, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_RESUME_RESP:
            JOLT_PRINT_FATAL("RESUME_RESP\n");
            if (__jolt_trans_resp(p_st_conn, p_st_sess, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_CALL_RESP:
            JOLT_PRINT_FATAL("CALL_RESP\n");
            if (__jolt_call_resp(p_st_conn, p_st_sess, p_st_jolt_packet, p_st_hash_report) != FR_SUCC)
                goto error;
            break;
        case APM_JOLT_JOPCODE_LOGOFF_RESP:
            JOLT_PRINT_FATAL("LOGOFF_RESP\n");
            break;
        default:
            ;
    }

    return FR_SUCC;
error:
    return FR_FAIL;
}
